<template>
  <view class="container">
    <view class="content">
      <view class="header_txt">
        <view class="back"
              @click="backHandler">
          <image src="/static/img/back3.png"></image>
        </view>
        <view class="title"> 试题列表 </view>
      </view>
      <view class="none_msg"
            v-if="questionBankList.length==0">
        <image src="../../static/image/offerxq_img_k@2x.png"
               mode=""></image>
        <view class="none_title">暂无信息</view>
      </view>
      <view class="list_box">
        <view class="list_item"
              v-for="item in questionBankList"
              :key="item.id">
          <view class="list_left">
            <view class="list_title">{{item.name}}</view>
            <view class="list_info">{{item.answer_num}}已做 | 答题时长 {{item.answer_time}}分钟</view>
          </view>
          <view class="list_right">
            <image src="../../static/image/mkst_ico_bj@2x.png"
                   @click="CreatOrder(item.id,item.is_buy)"></image>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      questionBankList: [],
      classid: null,
      order_sn: '',
      orderid: null,
      price: '',
      queryParams: { type: null, q_id: null }
    }
  },
  onLoad(options) {
    console.log(options)
    this.classid = options.classid
    this.getQuestionBankList(options.typeid, options.classid)
  },
  onShow() {},

  methods: {
    backHandler() {
      uni.navigateBack({
        delta: 1
      })
    },
    async CreatOrder(id, is_buy) {
      if (is_buy == 1) {
        this.queryParams = { type: this.classid, q_id: id }
        const { data } = await this.$http.post('/order/create', this.queryParams)
        console.log(data)
        this.order_sn = data.data.order_sn
        this.price = data.data.price
        this.orderid = data.data.id
        uni.navigateTo({
          url: `../payment/payment_other?oid=${this.orderid}&price=${this.price}&id=${id}&orderSn=${this.order_sn}`
        })
      } else {
        this.queryParams = { type: 2, q_id: id }
        const { data } = await this.$http.post('/order/create', this.queryParams)
        console.log(data)
        this.order_sn = data.data.order_sn
        this.price = data.data.price
        this.orderid = data.data.id
        uni.navigateTo({
          url: `../payment/payment_other?oid=${this.orderid}&price=${this.price}&id=${id}&orderSn=${this.order_sn}`
        })
      }
    },

    //question_bank/index
    async getQuestionBankList(typeid, classid) {
      const { data } = await this.$http.post('/question_bank/index', { type: typeid, class_id: classid })
      console.log(data)
      this.questionBankList = data.data
    }
  }
}
</script>

<style lang="scss">
/* 头部区域 */
.header_txt {
  width: 750rpx;
  overflow: hidden;
  height: 88rpx;
  background-color: #fff;

  .back {
    position: absolute;
    top: 14rpx;
    left: 14rpx;
    width: 60rpx;
    height: 60rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    image {
      width: 48rpx;
      height: 48rpx;
    }
  }

  .right {
    position: absolute;
    top: 14rpx;
    right: 14rpx;
    width: 60rpx;
    height: 60rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .title {
    text-align: center;
    width: 750rpx;
    height: 88rpx;
    line-height: 88rpx;
    font-size: 32rpx;
    font-weight: bold;
  }
}
.content {
  width: 100%;
  height: 100%;
}
.list_box {
  width: 100%;
  height: auto;
  background-color: #ffffff;
  margin-top: 20rpx;
  padding: 0 30rpx;
}
.list_item {
  width: 100%;
  height: 170rpx;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1rpx solid #f5f5f5;
}
.list_right {
  height: 100%;
  display: flex;
  align-items: flex-end;
  padding-bottom: 30rpx;
}
.list_right image {
  width: 29rpx;
  height: 26rpx;
}
.list_left {
  height: 100%;
  width: 85%;
  padding: 25rpx 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-direction: column;
}
.list_title {
  width: 80%;
  font-size: 28rpx;
  font-family: PingFang SC;
  font-weight: bold;
  color: #333333;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box; /*将对象作为弹性伸缩盒子模型显示。*/
  -webkit-line-clamp: 2; /*设置需要显示的行数*/
  -webkit-box-orient: vertical; /*设置伸缩盒子的子元素排列方式(从上到下垂直排列)*/
}
.list_info {
  font-size: 24rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #999999;
  margin-top: 10rpx;
}
.none_msg {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  margin-top: 300rpx;
}

.none_msg image {
  width: 354rpx;
  height: 253rpx;
}

.none_title {
  font-size: 26rpx;
  font-family: PingFang SC;
  font-weight: 500;
  color: #666666;
  margin-top: 40rpx;
}
</style>
